#!/bin/sh
set -e

# If there's no bootstrap version, compile it
if [ ! -f rtc.bootstrap ]; then
    echo "Building bootstrap compiler..."
    # Building bootstrap compiler
    as --32       -o rtc.bootstrap.o reset.bootstrap.S
    ld -melf_i386 -o rtc.bootstrap   rtc.bootstrap.o
fi

echo "Building compiler..."
./rtc.bootstrap reset.rt
mv output.S rtc.S
as --32       $@ -o rtc.o rtc.S
ld -melf_i386    -o rtc   rtc.o
echo "Compiler was built successfully!"
